package com.ihcy.base.core.enums;

import java.util.EnumSet;
import java.util.Objects;

public class EnumUtil {
    /**
     *
     * @param enumClass 目标枚举
     * @param code 传入值
     */
    public static <E extends Enum<E>, T> EnumAbility<T> getEnumByCode(Class<E> enumClass, T code) {
        if (code == null) {
            return null;
        }
        EnumSet<E> es = EnumSet.allOf(enumClass);
        for (E anEnum : es) {
            if (anEnum instanceof EnumAbility) {
                if (((EnumAbility) anEnum).codeEquals(code)) {
                    return (EnumAbility<T>) anEnum;
                }
            }
        }
        return null;
    }


}